<#if roles.canWork>
<div class="col-md-12 plan-work">
	<div class="panel panel-primary">
		<div class="panel-heading">
			<h3 class="panel-title">
				<i class="icon-tasks icon-large"></i>
				7日内待完成的工作任务
			</h3>
		</div>
		<#if workPlan??>
		<table class="table table-hover">
			<tr>
				<th class="text-center" width="55"></th>
				<th class="text-center" width="70">状态</th>
				<th class="text-center" width="115">里程碑</th>
				<th class="text-center" width="180">工作内容</th>
				<th class="text-center" width="100">创建人</th>
				<th class="text-center" width="225">合同编号</th>
				<th class="text-center">合同名称</th>
			</tr>
			<#list workPlan as p>
			<!--  -->
			<#assign url=((p.contract.mainContract)?string('contract','sub-contract'))!'contract'>
			<tr class="${((p.completed)?string('text-deleted',((p.overDate)?string('text-danger',''))))}" style="cursor: pointer;" data-url="${url}" data-cid="${p.contract.id}">
				<td class="text-center"><#if p.completed?? && !p.completed>
					<div class="btn btn-danger btn-xs work-by-plan" data-id="${p.contract.id}" data-plan-id="${p.id}">完成</div> </#if>
				</td>
				<td class="text-center cell-for-open">${((p.completed)?string('已完成','未完成'))}</td>
				<td class="text-center cell-for-open">${(p.datePoint?string('yyyy-MM-dd'))!'-'}</td>
				<td class="text-center cell-for-open">${p.work}</td>
				<td class="text-center cell-for-open">${p.creater.name}</td>
				<td class="text-center cell-for-open">${p.contract.no}</td>
				<td class="text-center cell-for-open">${p.contract.name}</td>
			</tr>
			</#list>
		</table>

		<script type="text/javascript">
			require([ 'suredy' ], function() {
				// 打开合同
				$('.plan-work').on('click', '.cell-for-open', function() {
					var $this = $(this);
					var tr = $this.parent('tr');
					var url = tr.data('url');
					var cid = tr.data('cid');

					window.open('${request.contextPath}/' + url + '/view/' + cid + '/%23tab-head6', '_blank');
				});

				// 通过付款计划付款
				$('.plan-work').on('click', '.btn.work-by-plan', function() {
					if (!confirm('是否确认执行此操作？')) {
						return false;
					}

					var $this = $(this);
					var id = $this.data('id'); // 合同
					var planId = $this.data('plan-id'); // 付款计划

					$.ajax({
						url : '${request.contextPath}/contract/work-completed-by-plan',
						type : 'post',
						data : {
							id : id,
							planId : planId
						},
						dataType : 'json',
						success : function(result, textStatus, jqXHR) {
							if (!result || !result.success) {
								var msg = (result && result.msg) || '操作失败！';
								alert(msg);
								return false;
							}

							Suredy.loadContent('${request.contextPath}/front-page');
						},
						error : function(jqXHR, textStatus, errorThrown) {
							alert('操作失败！\n\n' + errorThrown);
						}
					});
				});
			});
		</script>
		<#else>
		<div class="panel-body text-danger">暂无工作计划！</div>
		</#if>
	</div>
</div>
</#if>
